<!--
Copyright 2012 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<!DOCTYPE html>
<style>
.animContainer {
  position: absolute;
  left: 0px;
}

.anim {
  left: 0px;
  width: 100px;
  height: 25px;
  background-color: #FAA;
  position: relative;
}

.expected {
  border-right: 1px solid black;
}

#ca {
  top: 50px;
  width: 400px;
}

#cb {
  top: 150px;
  width: 200px;
}

#cc {
  top: 250px;
  width: 200px;
}

#cd {
  top: 350px;
  width: 200px;
}

</style>

<div>Right edge of each box should align with black line at end of test. Note
that the position of the last element in each group is approximate.</div>

<div class="animContainer" id="ca">
  <div style="width: 600px;" class="expected"><div class="anim a"></div></div>
  <div style="width: 600px;" class="expected"><div class="anim b"></div></div>
</div>

<div class="animContainer" id="cb">
  <div style="width: 200px;" class="expected"><div class="anim a"></div></div>
  <div style="width: 200px;" class="expected"><div class="anim b"></div></div>
</div>

<div class="animContainer" id="cc">
  <div style="width: 200px;" class="expected"><div class="anim a"></div></div>
  <div style="width: 200px;" class="expected"><div class="anim b"></div></div>
</div>

<div class="animContainer" id="cd">
  <div style="width: 600px;" class="expected"><div class="anim a"></div></div>
  <div style="width: 600px;" class="expected"><div class="anim b"></div></div>
</div>

<script src="../bootstrap.js"></script>
<script>
"use strict";

var containers = ["ca", "cb", "cc", "cd"];

var directions = ["normal", "reverse", "alternate", "alternate-reverse"];

var animation = [{left: "100px"}, {left: "500px"}];

// We use a new group for each animation to avoid coupling due to the intrinsic
// iterationDuration of a par group.
var group = function(direction) {
  return new ParGroup([], {iterationCount: 2.0, direction: direction});
};
var groupWithFixedDuration = function(direction) {
  return new ParGroup([],
      {iterationCount: 2.0, direction: direction, iterationDuration: 4.0});
};

for (var i = 0; i < directions.length; i++) {
  var container = document.getElementById(containers[i]);
  var direction = directions[i];

  // Interaction of default start time with parent iterations. At the time of
  // addition, the child picks up a start time of zero. The parent then updates
  // its iterationDuration and its iteration time jumps, causing the child to start
  // playing part way through the animation.
  var group1 = group(direction);
  document.timeline.play(group1);
  var group2 = groupWithFixedDuration(direction);
  document.timeline.play(group2);

  timing_test(function() {
      at(0.75, function(container, group1, group2) {
        return function() {
          group1.append(new Animation(container.getElementsByClassName("a")[0],
              animation, {iterationDuration: 1.0}));
          group2.append(new Animation(container.getElementsByClassName("b")[0],
              animation, {iterationDuration: 1.0}));
        };
      }(container, group1, group2))
    });
}
</script>
